package com.edu.koTA07.takingOrder;



import java.util.ArrayList;

import android.app.ListActivity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

import com.edu.koTA07.XmlDataSet.CustomerXmlDataSet;
import com.edu.koTA07.adapter.CustomersListAdapter;
import com.edu.koTA07.bean.CustomerBean;
import com.edu.koTA07.sqlHelper.SQLHelper;
import com.edu.koTA07.utils.CustomerUtils;

public class ListToko extends ListActivity {	
	protected static final String TAG = null;
	private ListView customersList;
    CustomerXmlDataSet customer = null;
    ArrayList<CustomerBean> currentData;
	SQLiteDatabase database;
	SQLHelper helper;
	CustomerBean customerBean;
	CustomersListAdapter customersListAdapter;
	
	CustomerUtils util;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Log.d(TAG, "oke");
		setContentView(R.layout.list_toko);
		util = new CustomerUtils(this);
		init();
	}
	
	public void init(){
		//customerBean = new CustomerBean();
    	customersList = (ListView) findViewById(android.R.id.list);
    	currentData = new ArrayList<CustomerBean>();
        currentData = util.loadData();
        customersListAdapter = new CustomersListAdapter(this, currentData);
        customersList.setAdapter(customersListAdapter);
        customersList.setOnItemClickListener(new OnItemClickListener() {
			public void onItemClick(AdapterView<?> parent, View view,
			        int position, long id) {
				customerBean = customersListAdapter.getItem(position);
				String customer = customerBean.getNamaToko();
				String iDcustomer = customerBean.getIDCustomer();
				Log.d(TAG, customer);
				Log.d(TAG, iDcustomer);
				if (customer!=null){
					Intent intent = new Intent(ListToko.this, StatusKunjungan.class);
		            intent.putExtra("nama_toko", customer);
		            intent.putExtra("id_toko", iDcustomer);
	                startActivity(intent);				
				}
			}

		});	
	}

}   

